var app = getApp(),
  a = app.requirejs("core");
Page({
  data: {
    page: 1,
    loaded: false,
    list:[],
    integral:0,
    show:false
  },
  onLoad: function () {

    a.setting();
    var that = this;
    that.setData({
      userinfo: getApp().getCache("userinfo")
    });
    that.getlist();
  },
  getlist: function () {
    var that = this,
      page = that.data.page;
    a.get('Integral/integralinfo', { page: page,uid:app.getCache('userinfo').uid }, function (t) {
      if (t.code == 0) {
        that.setData({ integral: t.info.integral})
        if (t.info.info.length > 0) {
          that.setData({
            list: that.data.list.concat(t.info.info),
            page: page + 1,
            show:true
          })
          if (t.info.info.length < 20) {
            that.setData({ loaded: true })
          }
        }
        else {
          that.setData({
            loaded: true,
          })
        }

      } else {
        a.alert(t.msg);
      }
    }, !that.data.show)
  },
  speed: function () {
    var that = this,
      page = that.data.page_s;
    a.get('Integral/speedrank', { page: page }, function (t) {
      if (t.code == 0) {
        if (t.info.length > 0) {
          that.setData({
            speed_list: that.data.speed_list.concat(t.info),
            show: true,
            page_s: page + 1,
          })
          if (t.info.length < 20) {
            that.setData({ loaded_s: true })
          }
        }
        else {
          that.setData({
            loaded_s: true,
          })
        }

      } else {
        a.alert(t.msg);
      }
    }, !that.data.show)
  },
  to_shop:function(){
      a.jump('/yb_shop/pages/member/integral/shop');
  },
  onPullDownRefresh: function () {
      this.setData({
        list: [],
        page: 1,
        loaded: false
      });
      this.getlist();
  },
  onReachBottom: function () {
      this.loaded || this.getlist();
  }
});